<template>
    <!-- 书籍的详情页，可以返回首页或搜索页 -->
    <div>
        <!-- 头部导航，可以回到首页、搜索页 -->
        <div class="book-detail-nav">
            <div 
                class="btn-index"
                @click="goIndex">
                <i class="fa fa-desktop" aria-hidden="true"></i> 返回首页
            </div>
            <div class="title">小说详情</div>
            <div 
                class="btn-search"
                @click="goSearch">
                <i class="fa fa-search" aria-hidden="true"></i> 搜索
            </div>
        </div>
        <!-- 小说的细节 -->
        <div class="book-item">
            <div class="photo">
                <img src="@/assets/images/index/logo-no-color.png" alt="">
            </div>
            <div class="book-info" v-if="book_data != null">
                <div class="title">{{book_data.bookName}}({{book_name}})</div>
                <div>作者：<span>{{book_data.author}}</span></div>
                <div>字数：<span>{{book_data.fontNum}}</span></div>
                <div>已有<span>{{book_data.readingNum}}人次</span>读过此书</div>
            </div>
        </div>
        <!-- 立即阅读、加入书架 -->
        <div class="btn-list">
            <router-link to="/reading/9999/1/must" class="btn-read">立即阅读</router-link>
            <a class="btn-bookshelf">XXXX</a>
        </div>
        <!-- 小说新篇章 -->
        <div class="new-chater"  v-if="book_data != null">
            <router-link to="/reading/9999/4/must">
                <span class="new-c-l">最新</span>
                {{book_data.newChapter}}
                <span class="new-c-r r">{{book_data.updataTime}}</span>
            </router-link>

        </div>
        <!-- 小说的简介 -->
        <div class="book-scripe"  v-if="book_data != null">
            <div class="title"><i class="fa fa-map-signs" aria-hidden="true"></i>作品简介</div>
            {{book_data.bookScripe}}
        </div>
    </div>
</template>

<script>
export default {
    name: "bookDatali",
    data() {
        return {
            book_id: '',
            book_name: '',
            book_data: null,
        }
    },
    methods: {
        goIndex() {
            this.$router.push({path:"/"});
        },
        goSearch() {
            this.$router.push({path:"/search"});
        }
    },
    created() {
        this.$axios.get('./static/bookDetail.json').then(response => {
            this.book_data = response.data;
            // console.log(this.book_data);
            if(this.$route.query.bookName) {
                this.book_name = this.$route.query.bookName;
            }
        }, response => {
            console.log("error");
            alert('网络请求错误')
        });
    },
    beforeRouteLeave(to,from,next) {
        if(to.name == 'Reading'){
            let user = this.$mycookie.getCookie('un');
            if(user == undefined || ( user.length <= 0 ) ) {
                this.$router.push({path:'/sign_in'})
            }else {
                next();
            }
        }else {
            next();
        }
    }
}
</script>

<style lang="scss" scoped>
.book-detail-nav {
    padding: 0 10px;
    height: 50px;
    line-height: 50px;
    font-size: 16px;
    text-align: center;
    position: relative;
    background-color: #333;
    .title {
        width: 100%;
        font-size: 20px;
        color: white;
    }
    
    .btn-search,
    .btn-index {
        color: #ccc;
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
    }
    .btn-search {
        right: 10px;
    }
}
.book-item {
    padding: 8px 14px;
    display: flex;
    font-size: 13px;
    background-color: #fafafa;
    color: #888;
    .photo {
        img {
            background-color: #999;
            width: 74px;
            height: 98px;
            margin-right: 10px;
        }
    }
    .book-info {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .title {
            font-size: 16px;
            color: black;
        }
        span {
            color: black;
        }
    }
}
.btn-list {
    display: flex;
    justify-content: space-between;
    padding: 14px 8px 0 8px;
    font-size: 18px;
    & > a {
        height: 36px;
        line-height: 36px;
        width: 48%;
        border: 1px solid #B33836;
        border-radius: 2px;
        text-align: center;
    }
    .btn-read {
        background-color: #B33836;
        color: white;
    }
    .btn-bookshelf {
        background-color: white;
        color: #B33836;
    }
}

.new-chater {
    margin: 14px 8px;
    font-size: 14px;
    height: 30px;
    line-height: 30px;
    overflow: hidden;
    span {
        font-size: 12px;
    }
    .new-c-l {
        display: inline-block;
        height: 14px;
        line-height: 16px;
        padding: 1px;
        border:1px solid #FF4643;
        color: #FF4643;
    }
    .new-c-r {
        color: #999;
    }
}
.book-scripe {
    margin: 14px 8px;
    font-size: 16px;
    color: #333;
    line-height: 30px;
    .title {
        font-size: 18px;
        margin-bottom: 14px;
    }
}
</style>